
class OutClass {
    private int data1 = 10;
    public int data2 = 20;
    public static int data3 = 30;

   /* 实例内部类
    1.如何实例化 实例内部类对象？
    2.实例内部类中不能定义静态成员变量
    */
    class InnerClass {
        public int data1 = 111;
        public int data4 = 40;
        private int data5 = 50;
        //实例内部类中不能定义静态成员变量:static不依赖于对象
       //如果加一个final就能正常运行，因为final修饰的是常量，常量在编译时就已经确定了
       //public static int data6 = 60;
       public static final int data6 = 60;

        public void testInner() {
            System.out.println("testInner");
            //实例内部类 是存在外部类的this的
            System.out.println(OutClass.this.data1);
            System.out.println(data1);
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);

        }
    }

    public void testOut() {
        InnerClass innerClass = new InnerClass();
        System.out.println(innerClass.data5);
    }
}


class OutClass2 {
    public int data1 = 10;
    private int data2 = 20;
    public static int data3 = 30;

    /* 静态内部类
    * 1.如何实例化静态内部类对象
    * 2.如何在静态内部类当中访问外部内部类的非静态成员
    * */
    static class InnerClass {
        public int data4 = 40;
        private int data5 = 50;
        public static int data6 = 60;

        public void testInner() {
            System.out.println("testInner");
            OutClass2 outClass2 = new OutClass2();
            System.out.println(outClass2.data1);
            System.out.println(outClass2.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);

        }
    }
}

class OutClass3 {
    //局部内部类
    public void test() {
        class Inner {
            public int data1 = 10;
        }
        //只能在该方法体内部使用，其他位置都不能用
        Inner inner = new Inner();
        System.out.println(inner.data1);
    }
}

class Student implements Comparable<Student> {

    @Override
    public int compareTo(Student o) {
        return 0;
    }
}

interface Shape {
    void draw();
}

public class Test {
    public static void main(String[] args) {
        Comparable<Student> comparable = new Student();

        new Comparable<Student>() {
            @Override
            public int compareTo(Student o) {
                return 0;
            }
        };
        //
        int a = 10;
        new Shape() {
            @Override
            public void draw() {
                //在匿名内部类当中，访问的变量是不可以改变的
                //a = 99;
                System.out.println("矩形"+a);
            }
        }.draw();
    }
    public static void main2(String[] args) {
        OutClass2.InnerClass innerClass = new OutClass2.InnerClass();
        innerClass.testInner();
    }
    public static void main1(String[] args) {
        OutClass outClass = new OutClass();
        OutClass.InnerClass innerClass = outClass.new InnerClass();
        //上面两行代码可以写成：
        OutClass.InnerClass innerClass1 = new OutClass().new InnerClass();
        innerClass1.testInner();
    }
}
